/*
* This file is part of wxSmith plugin for Code::Blocks Studio
* Copyright (C) 2006-2007  Bartlomiej Swiecki
*
* wxSmith is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wxSmith is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
*
* $Revision: 10874 $
* $Id: wxsmith.h 10874 2016-07-16 20:00:28Z jenslody $
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-17.xx/src/plugins/contrib/wxSmith/wxsmith.h $
*/

#ifndef WXSMITH_H
#define WXSMITH_H

#include <wx/splitter.h>
#include <wx/scrolwin.h>

#include <cbplugin.h>
#include <settings.h>
#include <sdk_events.h>
#include <tinyxml.h>

#include "wxsstoringsplitterwindow.h"
#include "wxsresourcetree.h"

class wxsProject;
class wxsItem;
class wxsResource;

/**
 * 实现功能:主插件将处理史密斯(wxSmith)的大部分工作
 *
 * This plugin is responsible for managing wxsProject classes - addition to
 * standard cbProject class and is used for global notifications like
 * selecting item.
 *
 * 这个插件负责管理资源项目(wxsProject)类-添加到标准项目(cbProject)类中,并用于全局通知,如选择项.
 *
 * This class is a singleton, is registered in OnAttach and unregistered in
 * OnRelease.
 *
 * 这个类是一个独立类,在OnAttach中注册,在OnRelease中取消注册
 */
class wxSmith : public cbPlugin
{
    public:
        wxSmith();
        ~wxSmith();

        /**
         * @brief Function returning singleton instance
         * 功能: 函数返回单实例
         * */
        static wxSmith* Get() { return m_Singleton; }

        /**
         * @brief Getting group in configuration dialog
         * 功能:在配置对话框中获取组
         * */
        int GetConfigurationGroup()  const { return cgEditor; }

        /**
         *@brief Creating configuration panel
         * 功能:创建配置面板
         * */
        cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent);

        /**
         * @brief Generating extra configuration panel inside project options
         * 功能:在项目选项内生成额外的配置面板
         * */
        virtual cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project);

        /**
         * @brief This function will add entries into menu
         * 功能:此功能将在菜单中添加条目
         * */
        void BuildMenu(wxMenuBar* menuBar);

        void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0);
        bool BuildToolBar(wxToolBar* toolBar);
        void OnAttach();
        void OnRelease(bool appShutDown);

        /**
         * @brief Registering scripting stuff
         * 功能: 注册脚本
         * */
        void RegisterScripting();

        /** 
         * @brief unregistering scripting stuff
         * 功能:取消注册(卸载插件)脚本
         * */
        void UnregisterScripting();

        /** 
         * @brief Getting wxsProject addition for given cbProject
         * 功能:获取给定项目(cbProject)的添加资源项目(wxsProject),即在给定的项目里获取史密斯项目
         * */
        wxsProject* GetSmithProject(cbProject* Proj);

        /**
         * @brief Getting cbProject class from wxsProject addition
         * 功能:从添加的资源项目(wxsProject)里获取项目(cbProject)类
         * */
        cbProject* GetCBProject(wxsProject* Proj);

        /**
         * @brief Helper operator used to convert C::B projects to wxS projects
         * 功能: 用于将C::B项目转换为资源项目(wxsProject)的辅助器运算符重载
         * */
        inline wxsProject* operator[](cbProject* Proj) { return GetSmithProject(Proj); }

        /**
         * @brief Helper operator used to convert wxS projects to C::B projects
         * 功能:用于将资源项目(wxsProject)转换为C::B项目(cbProject)的辅助器运算符重载
         *
         * */
        inline cbProject* operator[](wxsProject* Proj) { return GetCBProject(Proj); }

        /**
         * @brief Bringing up the resources tab to the view
         * 功能: 将"资源"选项卡调到视图中
         * */
        void ShowResourcesTab();

    private:

        //声明C::B项目(cbProject)和资源项目(wxsProject)的哈希表
        WX_DECLARE_HASH_MAP(cbProject*,wxsProject*,wxPointerHash,wxPointerEqual,ProjectMapT);
        typedef ProjectMapT::iterator ProjectMapI;

        ///< @brief Map binding all cbProject classes with wxsProject ones
        ///< 用于:将所有项目(cbProject)类与资源项目(wxsProject)类进行映射绑定[哈希表]
        ProjectMapT m_ProjectMap;
        ///< @brief Splitter window used to divide resource browser and property grid
        ///< 用于:划分资源浏览器和属性网格的拆分器窗口
        wxsStoringSplitterWindow* m_Splitter;
        ///< @brief Parent panel for resource browser
        ///< 用于:资源浏览器的父面板
        wxPanel* m_ResourceBrowserParent;
        ///< @brief Parent for property browser
        ///< 用于:属性浏览器的父级
        wxPanel* m_PropertyBrowserParent;
        ///< @brief Project hook identifier used when deleting hook
        ///< 用于:删除挂钩时使用的项目挂钩标识符
        int m_HookId;

        ///< @brief Singleton object
        ///< 用于:单例对象
        static wxSmith* m_Singleton;

        /**
         * @brief Procedure called when loading/saving project, used to load/save additional configuration from/to .cbp file
         * 功能:加载/保存项目时调用的过程,用于从/到项目(.cbp)文件加载/保存附加配置
         * */
        void OnProjectHook(cbProject*,TiXmlElement*,bool);

        /**
         * @brief Procedure called when project has been loaded
         * 功能: 加载项目时调用的过程
         * */
        void OnProjectOpened(CodeBlocksEvent& event);

        /**
         * @brief Procedure called when closing project, removes additional stuff associated with project
         * 功能: 关闭项目时调用的过程,删除与项目关联的其他内容
         * */
        void OnProjectClose(CodeBlocksEvent& event);

        /**
         * @brief Procedure called when some project has been renamed - it will update resource browser
         * 功能: 重命名某个项目时调用的过程-它将更新资源浏览器
         * */
        void OnProjectRenamed(CodeBlocksEvent& event);

        /**
         * @brief Called when clicked "Configure..." from wxSmith menu
         * 功能: 在史密斯(wxSmith)菜单中单击"配置..."时调用
         * */
        void OnConfigure(wxCommandEvent& event);

        /**
         * @brief Called for any menu, used to find possible "Add ...." entries
         * 功能:调用任何菜单,用于查找可能的"添加..."条目
         * */
        void OnMenu(wxCommandEvent& event);

        /**
         * @brief Function building resource and properties browser
         * 功能: 构建资源和属性浏览器的函数
         * */
        void BuildBrowsers();

        /**
         * @brief Function Generating background panes for resource and property browsers
         * 功能: 为资源和属性浏览器生成背景面板的函数
         * */
        void BuildBrowserParents();

        /**
         * @brief Function allowing to recover invalid wxs file
         * 功能: 允许恢复无效资源(wxs)文件的函数
         * */
        static bool RecoverWxsFile( const wxString& WxsResourceSettings );

        void OnViewBrowsers(wxCommandEvent& event);
        void OnViewResourceBrowser(wxCommandEvent& event);
        void OnViewPropertyBrowser(wxCommandEvent& event);
        void OnUpdateUI(wxUpdateUIEvent& event);

        friend class wxSmithMime;
        DECLARE_EVENT_TABLE()
};

/**
 * @brief Helper function to easily access wxSmith plugin
 * 功能:帮助函数可以轻松访问史密斯(wxSmith)插件
 * */
inline wxSmith* wxsPlugin() { return wxSmith::Get(); }

/**
 * @brief Helper function to access project converter (wxSmith project <-> C::B project)
 * 功能:访问项目转换器的帮助函数(史密斯项目(wxSmith project)<->C::B project)
 *
 * */
inline wxSmith* wxsProjectConv() { return wxSmith::Get(); }

#endif

